package marmalius;
/*
	Effectue la gestion ...
	modifie par Metos [EOAH]
*/

public class prayerhandler {
	private static int playerpraying[] = new int[5001];
	private static int prayused[] = new int[5001];
	public static boolean retrib[] = new boolean[5001];
	public static boolean pmage[] = new boolean[5001];
	public static boolean pmelee[] = new boolean[5001];
	public static boolean prange[] = new boolean[5001];
	public static boolean pitem[] = new boolean[5001];
	public static boolean smite[] = new boolean[5001];
	public static boolean redem[] = new boolean[5001];
	
	public prayerhandler () {
		for (int i = 0; i < 5001; i++) {
			playerpraying[i] = -1;
			prayused[i] = -1;
		}
	}
	
	public static int gethicon (int i) {
		switch (i) {
			case 15: // '\017'
				return 1;
			case 14: // '\016'
				return 2;
			case 13: // '\r'
				return 4;
			case 16: // '\020'
				return 8;
			case 17: // '\021'
				return 32;
			case 18: // '\022'
				return 16;
		}
		return 0;
	}
	
	public static int getglowid (int i) {
		switch (i) {
			case 1: // '\001'
				return 83;
			case 2: // '\002'
				return 84;
			case 3: // '\003'
				return 85;
			case 4: // '\004'
				return 86;
			case 5: // '\005'
				return 87;
			case 6: // '\006'
				return 88;
			case 7: // '\007'
				return 89;
			case 8: // '\b'
				return 90;
			case 9: // '\t'
				return 91;
			case 10: // '\n'
				return 92;
			case 11: // '\013'
				return 93;
			case 12: // '\f'
				return 94;
			case 13: // '\r'
				return 95;
			case 14: // '\016'
				return 96;
			case 15: // '\017'
				return 97;
			case 16: // '\020'
				return 98;
			case 17: // '\021'
				return 99;
			case 18: // '\022'
				return 100;
		}
		return 10;
	}
	
	public static int getprayid (int i) {
		switch (i) {
			case 21233: 
				return 1;
			case 21234: 
				return 2;
			case 21235: 
				return 3;
			case 21236: 
				return 4;
			case 21237: 
				return 5;
			case 21238: 
				return 6;
			case 21239: 
				return 7;
			case 21240: 
				return 8;
			case 21241: 
				return 9;
			case 21242: 
				return 10;
			case 21243: 
				return 11;
			case 21244: 
				return 12;
			case 21245: 
				return 13;
			case 21246: 
				return 14;
			case 21247: 
				return 15;
			case 2171: 
				return 16;
			case 2172: 
				return 17;
			case 2173: 
				return 18;
		}
		return 0;
	}
	
	public static int lvl (int i) {
		switch (i) {
			case 1: // '\001'
				return 1;
			case 2: // '\002'
				return 4;
			case 3: // '\003'
				return 7;
			case 4: // '\004'
				return 10;
			case 5: // '\005'
				return 13;
			case 6: // '\006'
				return 16;
			case 7: // '\007'
				return 19;
			case 8: // '\b'
				return 22;
			case 9: // '\t'
				return 25;
			case 10: // '\n'
				return 28;
			case 11: // '\013'
				return 31;
			case 12: // '\f'
				return 34;
			case 13: // '\r'
				return 37;
			case 14: // '\016'
				return 40;
			case 15: // '\017'
				return 43;
			case 16: // '\020'
				return 46;
			case 17: // '\021'
				return 49;
			case 18: // '\022'
				return 52;
		}
		return 0;
	}
	
	private static boolean lvlreq (client client1, int j) {
		return client1.getLevelForXP(client1.playerXP[5]) >= lvl(j);
	}
	
	public static boolean pray (int i) {
		switch (i) {
			case 2171: 
			case 2172: 
			case 2173: 
			case 21233: 
			case 21234: 
			case 21235: 
			case 21236: 
			case 21237: 
			case 21238: 
			case 21239: 
			case 21240: 
			case 21241: 
			case 21242: 
			case 21243: 
			case 21244: 
			case 21245: 
			case 21246: 
			case 21247: 
				return true;
		}
		return false;
	}
	
	public static int getprayreduc (int i) {
		switch (i) {
			case 1: // '\001'
				return 30;
			case 2: // '\002'
				return 25;
			case 3: // '\003'
				return 20;
			case 4: // '\004'
				return 20;
			case 5: // '\005'
				return 18;
			case 6: // '\006'
				return 17;
			case 7: // '\007'
				return 10;
			case 8: // '\b'
				return 10;
			case 9: // '\t'
				return 10;
			case 10: // '\n'
				return 15;
			case 11: // '\013'
				return 14;
			case 12: // '\f'
				return 13;
			case 13: // '\r'
				return 10;
			case 14: // '\016'
				return 10;
			case 15: // '\017'
				return 10;
			case 16: // '\020'
				return 40;
			case 17: // '\021'
				return 5;
			case 18: // '\022'
				return 20;
		}
		return 0;
	}
	
	public static int getstatinc (int i) {
		switch (i) {
			case 1: // '\001'
				return 5;
			case 2: // '\002'
				return 5;
			case 3: // '\003'
				return 5;
			case 4: // '\004'
				return 10;
			case 5: // '\005'
				return 10;
			case 6: // '\006'
				return 10;
			case 10: // '\n'
				return 15;
			case 11: // '\013'
				return 15;
			case 12: // '\f'
				return 15;
			case 7: // '\007'
			case 8: // '\b'
			case 9: // '\t'
			default:
				return 0;
		}
	}
	
	public static int getpraytype (int i) {
		switch (i) {
			case 1: // '\001'
			case 2: // '\002'
			case 3: // '\003'
				return 1;
			case 4: // '\004'
			case 5: // '\005'
			case 6: // '\006'
				return 2;
			case 10: // '\n'
			case 11: // '\013'
			case 12: // '\f'
				return 3;
			case 7: // '\007'
			case 8: // '\b'
			case 9: // '\t'
			default:
				return 0;
		}
	}
	
	public static void IDSA (int i, int j) {
		client client1 = (client) PlayerHandler.getInstance().getPlayer(i);
		boolean flag = true;
		
		if (j == 2 || j == 5 || j == 11) {
			if (!client1.strprayon) {
				client1.strpraytype = getpraytype(j);
				client1.strprayon = true;
				client1.frame36(getglowid(j), 1);
			}
			else if (client1.strprayon && client1.strpraytype == getpraytype(j)) {
				client1.strpraytype = -1;
				client1.strprayon = false;
				flag = false;
				client1.frame36(getglowid(j), 0);
			}
			else if (client1.strprayon && client1.strpraytype != getpraytype(j)) {
				client1.frame36(getglowid(j), 0);
			}
		}
		if (j == 1 || j == 4 || j == 10) {
			if (!client1.defprayon) {
				client1.defpraytype = getpraytype(j);
				client1.defprayon = true;
				client1.frame36(getglowid(j), 1);
			}
			else if (client1.defprayon && client1.defpraytype == getpraytype(j)) {
				client1.defpraytype = -1;
				client1.defprayon = false;
				flag = false;
				client1.frame36(getglowid(j), 0);
			}
			if (client1.defprayon && client1.defpraytype != getpraytype(j)) {
				client1.frame36(getglowid(j), 0);
			}
		}
		if (j == 3 || j == 6 || j == 12) {
			if (!client1.attprayon) {
				client1.attpraytype = getpraytype(j);
				client1.attprayon = true;
				client1.frame36(getglowid(j), 1);
			}
			else if (client1.attprayon && client1.attpraytype == getpraytype(j)) {
				client1.attpraytype = -1;
				client1.attprayon = false;
				flag = false;
				client1.frame36(getglowid(j), 0);
			}
			else if (client1.attprayon && client1.attpraytype != getpraytype(j)) {
				client1.frame36(getglowid(j), 0);
			}
		}
		for (int k = 0; k < 5001; k++) {
			if (playerpraying[k] == i && !flag) {
				playerpraying[k] = -1;
				prayused[k] = -1;
				System.out.println("The prayer settings for this player has been set to -1.");
			}
		}
	}
	
	public static void pray (int i, int j) {
		client client1 = (client) PlayerHandler.getInstance().getPlayer(i);
		int k = getprayid(j);
		
		System.out.println((new StringBuilder()).append("PRAY ID: ").append(k).toString());
		if (k > 0) {
			if (client1.playerLevel[client1.playerPrayer] > 0) {
				//if (lvlreq(i, k)) {
				if (lvlreq(client1, k)) {
					boolean flag = true;
					for (int l = 0; l < 5001; l++) {
						if (l != i) {
							continue;
						}
						if (k == 2 || k == 5 || k == 11) {
							if (client1.strprayon && client1.strpraytype == getpraytype(k)) {
								flag = true;
							}
							else {
								flag = false;
							}
						}
						if (k == 1 || k == 4 || k == 10) {
							if (client1.defprayon && client1.defpraytype == getpraytype(k)) {
								flag = true;
							}
							else {
								flag = false;
							}
						}
						if (k == 2 || k == 6 || k == 12) {
							if (client1.attprayon && client1.attpraytype == getpraytype(k)) {
								flag = true;
							}
							else {
								flag = false;
							}
						}
						if (k > 0 && k < 7 || k > 9 && k < 13) {
							IDSA(i, k);
						}
						if (k == 13) {
							if (pmage[l]) {
								pmage[l] = false;
								client1.frame36(getglowid(k), 0);
								client1.headIcon = 0;
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else if (!prange[l] && !pmelee[l] && !pmage[l] && !retrib[l] && !redem[l] && !smite[l]) {
								pmage[l] = true;
								client1.frame36(getglowid(k), 1);
								client1.headIcon = gethicon(k);
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else {
								client1.frame36(getglowid(k), 0);
							}
						}
						if (k == 14) {
							if (prange[l]) {
								prange[l] = false;
								client1.frame36(getglowid(k), 0);
								client1.headIcon = 0;
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else if (!prange[l] && !pmelee[l] && !pmage[l] && !retrib[l] && !redem[l] && !smite[l]) {
								prange[l] = true;
								client1.frame36(getglowid(k), 1);
								client1.headIcon = gethicon(k);
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else {
								client1.frame36(getglowid(k), 0);
							}
						}
						if (k == 15) {
							if (pmelee[l]) {
								pmelee[l] = false;
								client1.frame36(getglowid(k), 0);
								client1.headIcon = 0;
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else if (!prange[l] && !pmelee[l] && !pmage[l] && !retrib[l] && !redem[l] && !smite[l]) {
								pmelee[l] = true;
								client1.frame36(getglowid(k), 1);
								client1.headIcon = gethicon(k);
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else {
								client1.frame36(getglowid(k), 0);
							}
						}
						if (k == 16) {
							if (retrib[l]) {
								retrib[l] = false;
								client1.frame36(getglowid(k), 0);
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else if (!prange[l] && !pmelee[l] && !pmage[l] && !retrib[l] && !redem[l] && !smite[l]) {
								retrib[l] = true;
								client1.frame36(getglowid(k), 1);
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else {
								client1.frame36(getglowid(k), 0);
							}
						}
						if (k == 17) {
							if (redem[l]) {
								redem[l] = false;
								client1.frame36(getglowid(k), 0);
								client1.headIcon = 0;
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else if (!prange[l] && !pmelee[l] && !pmage[l] && !retrib[l] && !redem[l] && !smite[l]) {
								redem[l] = true;
								client1.frame36(getglowid(k), 1);
								client1.headIcon = gethicon(k);
								client1.updateRequired = true;
								client1.appearanceUpdateRequired = true;
							}
							else {
								client1.frame36(getglowid(k), 0);
							}
						}
						if (k != 18) {
							continue;
						}
						if (smite[l]) {
							smite[l] = false;
							client1.frame36(getglowid(k), 0);
							client1.headIcon = 0;
							client1.updateRequired = true;
							client1.appearanceUpdateRequired = true;
							continue;
						}
						if (!prange[l] && !pmelee[l] && !pmage[l] && !retrib[l] && !redem[l] && !smite[l]) {
							smite[l] = true;
							client1.frame36(getglowid(k), 1);
							client1.headIcon = gethicon(k);
							client1.updateRequired = true;
							client1.appearanceUpdateRequired = true;
						}
						else {
							client1.frame36(getglowid(k), 0);
						}
					}
					int i1 = 0;
					do {
						if (i1 >= 5001) {
							break;
						}
						if (playerpraying[i1] == -1 && !flag) {
							playerpraying[i1] = i;
							prayused[i1] = k;
							System.out.println((new StringBuilder()).append("The prayer settings for this player has been set to ").append(i).toString());
							break;
						}
						if (flag && playerpraying[i1] == i) {
							playerpraying[i1] = -1;
							prayused[i1] = -1;
							break;
						}
						i1++;
					} while (true);
				}
				else {
					client1.frame36(getglowid(k), 0);
				}
			}
			else {
				client1.frame36(getglowid(k), 0);
			}
		}
	}
	
	public void process () {
		for (int i = 0; i < 5001; i++) {
			Player aplayer[] = PlayerHandler.getInstance().getAllPlayer();
			int j = aplayer.length;
			
			for (int k = 0; k < j; k++) {
				Player player = aplayer[k];
				if (player == null) {
					continue;
				}
				client client1 = (client) player;
				if (client1.strprayon && client1.playerLevel[client1.playerPrayer] > 0 && client1.spd == -1) {
					client1.spd = 10;
				}
				if (client1.defprayon && client1.playerLevel[client1.playerPrayer] > 0 && client1.dpd == -1) {
					client1.dpd = 10;
				}
				if (client1.attprayon && client1.playerLevel[client1.playerPrayer] > 0 && client1.apd == -1) {
					client1.apd = 10;
				}
				if (pmage[client1.playerId] && client1.playerLevel[client1.playerPrayer] > 0 && client1.pmpd == -1) {
					client1.pmpd = 10;
				}
				if (prange[client1.playerId] && client1.playerLevel[client1.playerPrayer] > 0 && client1.prpd == -1) {
					client1.prpd = 10;
				}
				if (pmelee[client1.playerId] && client1.playerLevel[client1.playerPrayer] > 0 && client1.pm2pd == -1) {
					client1.pm2pd = 10;
				}
				if (retrib[client1.playerId] && client1.playerLevel[client1.playerPrayer] > 0 && client1.retrib == -1) {
					client1.retrib = 10;
				}
				if (redem[client1.playerId] && client1.playerLevel[client1.playerPrayer] > 0 && client1.redem == -1) {
					client1.redem = 10;
				}
				if (smite[client1.playerId] && client1.playerLevel[client1.playerPrayer] > 0 && client1.smite == -1) {
					client1.smite = 10;
				}
			}
		}
	}
}
